home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWDebug / Sources / FWDbgStr.cpp next >
Encoding:
Text File  |  1996-04-25  |  6.9 KB  |  255 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWDbgStr.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #include <stddef.h>
  13.  
  14. // Need to include first so that FW_DEBUG is properly defined
  15. #ifndef FWDBGSTR_H
  16. #include "FWDbgStr.h"
  17. #endif
  18.  
  19. #ifdef FW_DEBUG
  20.  
  21. #ifndef SLPRIDEB_H
  22. #include "SLPriDeb.h"
  23. #endif
  24.  
  25. #ifndef FWPRIMEM_H
  26. #include "FWPriMem.h"
  27. #endif
  28.  
  29. #ifndef FWPRISTR_H
  30. #include "FWPriStr.h"
  31. #endif
  32.  
  33. #ifndef FWPRIDEB_H
  34. #include "FWPriDeb.h"
  35. #endif
  36.  
  37. #if defined(FW_BUILD_MAC) && !defined(__FILES__)
  38. #include <Files.h>
  39. #endif
  40.  
  41. #if defined(FW_BUILD_MAC) && !defined(__ERRORS__)
  42. #include <Errors.h>
  43. #endif
  44.  
  45. #if defined(FW_BUILD_MAC) && !defined(__TEXTUTILS__)
  46. #include <TextUtils.h>
  47. #endif
  48.  
  49. #if defined(FW_BUILD_MAC) && !defined(__SCRIPT__)
  50. #include <Script.h>
  51. #endif
  52.  
  53. #ifdef FW_BUILD_MAC
  54. #pragma segment FWDebug
  55. #endif
  56.  
  57. //========================================================================================
  58. //    CLASS FW_CDebugStream
  59. //========================================================================================
  60.  
  61. //----------------------------------------------------------------------------------------
  62. // FW_CDebugStream::EndLine
  63. //----------------------------------------------------------------------------------------
  64.  
  65. FW_CDebugStream& EndLine(FW_CDebugStream &stream)
  66. {
  67. #ifdef FW_BUILD_MAC
  68.     return stream.Write((void *) "\n", sizeof(char));
  69. #endif
  70. #ifdef FW_BUILD_WIN
  71.     return stream.Write((void *) "\n\r", sizeof(char) * 2);
  72. #endif
  73. }
  74.  
  75. //----------------------------------------------------------------------------------------
  76. // FW_CDebugStream::FW_CDebugStream
  77. //----------------------------------------------------------------------------------------
  78.  
  79. FW_CDebugStream::FW_CDebugStream()
  80. {
  81. }
  82.  
  83. //----------------------------------------------------------------------------------------
  84. // FW_CDebugStream::~FW_CDebugStream
  85. //----------------------------------------------------------------------------------------
  86.  
  87. FW_CDebugStream::~FW_CDebugStream()
  88. {
  89. }
  90.  
  91. //----------------------------------------------------------------------------------------
  92. // FW_CDebugStream::WriteChunk
  93. //----------------------------------------------------------------------------------------
  94.  
  95. FW_CDebugStream &FW_CDebugStream::WriteChunk(const void *data, size_t size)
  96. {
  97.     return Write(data, size);
  98. //    return Write((void *) " ", sizeof(char));
  99. }
  100.  
  101. //----------------------------------------------------------------------------------------
  102. // FW_CDebugStream::WriteBase10Number(long n)
  103. //----------------------------------------------------------------------------------------
  104.  
  105. FW_CDebugStream & FW_CDebugStream::WriteBase10Number(unsigned long n)
  106. {
  107.     char buf[20];
  108.     char *s = &buf[20];
  109.  
  110.     *--s = 0;
  111.     do
  112.     {
  113.         *--s = (char) (n % 10) + '0';
  114.         n /= 10;
  115.     } while (n != 0);
  116.  
  117.     return WriteChunk((void *) s, FW_PrimitiveStringLength(s));
  118. }
  119.  
  120. //----------------------------------------------------------------------------------------
  121. // FW_CDebugStream::WriteBase16Number(long n)
  122. //----------------------------------------------------------------------------------------
  123.  
  124. FW_CDebugStream & FW_CDebugStream::WriteBase16Number(unsigned long n)
  125. {
  126.     const char *digits = "0123456789ABCDEF";
  127.     char buf[11] = "0x00000000";
  128.     char *s = &buf[10];
  129.     
  130.     for (; n != 0; n /= 16)
  131.         *--s = digits[(short) (n % 16)];
  132.  
  133.     return WriteChunk((void *) buf, 10);
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. // FW_CDebugStream::operator<<(const signed char *string)
  138. //----------------------------------------------------------------------------------------
  139.  
  140. FW_CDebugStream & FW_CDebugStream::operator<<(const signed char *string)
  141. {
  142.     return WriteChunk((void *) string, FW_PrimitiveStringLength((const char *) string));
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. // FW_CDebugStream::operator<<(signed char c)
  147. //----------------------------------------------------------------------------------------
  148.  
  149. FW_CDebugStream & FW_CDebugStream::operator<<(signed char c)
  150. {
  151.     return WriteChunk((void *) &c, sizeof(char));
  152. }
  153.  
  154. //----------------------------------------------------------------------------------------
  155. // FW_CDebugStream::operator<<(long n)
  156. //----------------------------------------------------------------------------------------
  157.  
  158. FW_CDebugStream & FW_CDebugStream::operator<<(long n)
  159. {
  160.     if (n < 0)
  161.     {
  162.         Write((void *) "-", sizeof(char));
  163.         n = -n;
  164.     }
  165.     return WriteBase10Number(n);
  166. }
  167.  
  168. //----------------------------------------------------------------------------------------
  169. // FW_CDebugStream::operator<<(unsigned long n)
  170. //----------------------------------------------------------------------------------------
  171.  
  172. FW_CDebugStream & FW_CDebugStream::operator<<(unsigned long n)
  173. {
  174.     return WriteBase10Number(n);
  175. }
  176.  
  177. //----------------------------------------------------------------------------------------
  178. // FW_CDebugStream::operator<<(void *p)
  179. //----------------------------------------------------------------------------------------
  180.  
  181. FW_CDebugStream & FW_CDebugStream::operator<<(void *p)
  182. {
  183.     return WriteBase16Number((long) p);
  184. }
  185.  
  186.  
  187. //========================================================================================
  188. //    CLASS FW_CMacDebugStr
  189. //========================================================================================
  190.  
  191. //----------------------------------------------------------------------------------------
  192. // FW_CMacDebugStr::FW_CMacDebugStr
  193. //----------------------------------------------------------------------------------------
  194. #ifdef FW_BUILD_MAC
  195. FW_CMacDebugStr::FW_CMacDebugStr()
  196. {
  197.     fStr255[0] = 0;
  198. }
  199. #endif
  200.  
  201. //----------------------------------------------------------------------------------------
  202. // FW_CMacDebugStr::~FW_CMacDebugStr
  203. //----------------------------------------------------------------------------------------
  204. #ifdef FW_BUILD_MAC
  205. FW_CMacDebugStr::~FW_CMacDebugStr()
  206. {
  207.     Flush();
  208. }
  209. #endif
  210.  
  211. //----------------------------------------------------------------------------------------
  212. // FW_CMacDebugStr::Write
  213. //----------------------------------------------------------------------------------------
  214. #ifdef FW_BUILD_MAC
  215. FW_CDebugStream &FW_CMacDebugStr::Write(const void *data, size_t size)
  216. {
  217.     const char *p = (const char *)data;
  218.  
  219.     while (size-- != 0)
  220.     {
  221.         char ch = *p++;
  222.  
  223.         switch (ch)
  224.         {
  225.         case '\n':
  226.         case '\0':
  227.             Flush();
  228.             break;
  229.  
  230.         default:
  231.             if (fStr255[0] == 255)
  232.                 Flush();
  233.             fStr255[++fStr255[0]] = ch;
  234.             break;
  235.         }
  236.     }
  237.  
  238.     return *this;
  239. }
  240. #endif
  241.  
  242. //----------------------------------------------------------------------------------------
  243. // FW_CMacDebugStr::Flush
  244. //----------------------------------------------------------------------------------------
  245. #ifdef FW_BUILD_MAC
  246. void FW_CMacDebugStr::Flush()
  247. {
  248.     if (fStr255[0] != 0)
  249.         ::DebugStr(fStr255);
  250.     fStr255[0] = 0;
  251. }
  252. #endif
  253.  
  254. #endif // FW_DEBUG
  255.